<?php
/**
 * (jobs) email邮件
 */
namespace App\Jobs\ToolService\Email;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Mail\Message;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Mail;

/**
 * 邮件队列
 * Class SendEmailNotice
 * @package App\Jobs\ToolService
 */
class SendEmailNotice implements ShouldQueue
{

    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $data;

    /**
     * Create a new job instance.
     *
     * @param $data
     */
    public function __construct($data){
        $this->data = $data;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle(){

        $data = $this->data;
        if (empty($data)) die('no data!');

        $name = $data['name'];
        $pwd = $data['pwd'];

        //发送邮件通知
        Mail::send('products.plat-sku.list.useremail', compact('name', 'pwd'), function(Message $message) use ($data){
            //发起人
            $message->from($data['sendEmail']);
            //接收人
            $message->to($data['receiveEmail']);
            //主题
            $message->subject('开通账户邮件通知');
        });
    }

}
